package com.example.myblog.controller;


import com.example.myblog.exception.BaseException;
import com.example.myblog.result.ResponseBean;
import com.example.myblog.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 叶兴
 * @since 2022-09-29
 */
@RestController
@RequestMapping("/like")
public class LikeController {

    LikeService likeService;

    @Autowired
    public void setLikeService(LikeService likeService) {
        this.likeService = likeService;
    }

    /**
     * 新增一条对文章的点赞
     * @param blogId
     * @return
     * @throws BaseException
     */
    @PostMapping("/article/{blogId}")
    public ResponseBean likeArticle( @PathVariable String blogId) throws BaseException {
        likeService.insertLikeArticle(blogId);
        return ResponseBean.success();
    }

    /**
     * 新增一条对评论的点赞
     * @param blogId
     * @param commentId
     * @return
     * @throws BaseException
     */
    @PostMapping("/comment/{blogId}/{commentId}")
    public ResponseBean likeComment(@PathVariable String blogId,
                                    @PathVariable Integer commentId) throws BaseException {
        likeService.insertLikeComment(blogId,commentId);
        return ResponseBean.success();
    }
}
